package com.kwzjx.product.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.kwzjx.common.log.annotation.Log;
import com.kwzjx.common.log.enums.BusinessType;
import com.kwzjx.common.security.annotation.RequiresPermissions;
import com.kwzjx.product.domain.MallProductSkuInfo;
import com.kwzjx.product.service.IMallProductSkuInfoService;
import com.kwzjx.common.core.web.controller.BaseController;
import com.kwzjx.common.core.domain.Result;
import com.kwzjx.common.core.utils.poi.ExcelUtil;
import com.kwzjx.common.core.web.page.TableDataInfo;

/**
 * 商品SKUController
 *
 * @author kwzjx
 * @date 2024-05-31
 */
@RestController
@RequestMapping("/skuInfo")
public class MallProductSkuInfoController extends BaseController
{
    @Autowired
    private IMallProductSkuInfoService mallProductSkuInfoService;

    /**
     * 查询商品SKU列表
     */
    @RequiresPermissions("product:skuInfo:list")
    @GetMapping("/list")
    public Result<TableDataInfo> list(MallProductSkuInfo mallProductSkuInfo)
    {
        startPage();
        List<MallProductSkuInfo> list = mallProductSkuInfoService.selectMallProductSkuInfoList(mallProductSkuInfo);
        return getDataTable(list);
    }

    /**
     * 导出商品SKU列表
     */
    @RequiresPermissions("product:skuInfo:export")
    @Log(title = "商品SKU", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallProductSkuInfo mallProductSkuInfo)
    {
        List<MallProductSkuInfo> list = mallProductSkuInfoService.selectMallProductSkuInfoList(mallProductSkuInfo);
        ExcelUtil<MallProductSkuInfo> util = new ExcelUtil<MallProductSkuInfo>(MallProductSkuInfo.class);
        util.exportExcel(response, list, "商品SKU数据");
    }

    /**
     * 获取商品SKU详细信息
     */
    @RequiresPermissions("product:skuInfo:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return success(mallProductSkuInfoService.selectMallProductSkuInfoById(id));
    }

    /**
     * 新增商品SKU
     */
    @RequiresPermissions("product:skuInfo:add")
    @Log(title = "商品SKU", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody MallProductSkuInfo mallProductSkuInfo)
    {
        return toAjax(mallProductSkuInfoService.insertMallProductSkuInfo(mallProductSkuInfo));
    }

    /**
     * 修改商品SKU
     */
    @RequiresPermissions("product:skuInfo:edit")
    @Log(title = "商品SKU", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody MallProductSkuInfo mallProductSkuInfo)
    {
        return toAjax(mallProductSkuInfoService.updateMallProductSkuInfo(mallProductSkuInfo));
    }

    /**
     * 删除商品SKU
     */
    @RequiresPermissions("product:skuInfo:remove")
    @Log(title = "商品SKU", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        return toAjax(mallProductSkuInfoService.deleteMallProductSkuInfoByIds(ids));
    }

    @GetMapping("/listByProductId")
    public Result<List<MallProductSkuInfo>> listByProductId (MallProductSkuInfo mallProductSkuInfo) {
        List<MallProductSkuInfo> list = mallProductSkuInfoService.selectMallProductSkuInfoList(mallProductSkuInfo);
        return Result.success(list);
    }
}
